package com.bilgeadam.hibernate.program;

import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 *  
 * @author Bora SAYINER
 * @since Nov 15, 2014 3:57:55 PM
 * @version 1.0.0
 */
public class Driver {

	public static void main(String[] args) {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		{
			// Employee employee = new Employee();
			// employee.setFirstName("Nigar");
			// employee.setLastName("DURMUŞ");
			// {
			// Address workAddress = new Address();
			// workAddress.setCity("SAKARYA");
			// workAddress.setZipCode("12345");
			// employee.getAddresses().add(workAddress);
			// }
			// {
			// Address univAddress = new Address();
			// univAddress.setCity("ADAPAZARI");
			// univAddress.setZipCode("654321");
			// employee.getAddresses().add(univAddress);
			// }
			// {
			// Address courseAddress = new Address();
			// courseAddress.setCity("İSTANBUL");
			// courseAddress.setZipCode("987654");
			// employee.getAddresses().add(courseAddress);
			// }
			// session.save(employee);
			Employee employee = (Employee) session.get(Employee.class, 1L);
			System.out.println(employee);
			Set<Address> addresses = employee.getAddresses();
			for (Address address : addresses) {
				System.out.println(address);
			}
		}
		transaction.commit();
		session.close();
		sessionFactory.close();
	}
}
